home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / common / xbm.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-09  |  32.0 KB  |  1,335 lines

  1. /* The GIMP -- an image manipulation program
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  4.  * X10 and X11 bitmap (XBM) loading and saving file filter for the GIMP.
  5.  * XBM code Copyright (C) 1998 Gordon Matzigkeit
  6.  *
  7.  * The XBM reading and writing code was written from scratch by Gordon
  8.  * Matzigkeit <gord@gnu.org> based on the XReadBitmapFile(3X11) manual
  9.  * page distributed with X11R6 and by staring at valid XBM files.  It
  10.  * does not contain any code written for other XBM file loaders.
  11.  *
  12.  * This program is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program; if not, write to the Free Software
  24.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  25.  
  26. /* Release 1.0, 1998-02-04, Gordon Matzigkeit <gord@gnu.org>:
  27.  *   - Load and save X10 and X11 bitmaps.
  28.  *   - Allow the user to specify the C identifier prefix.
  29.  *
  30.  * TODO:
  31.  *   - Parsing is very tolerant, and the algorithms are quite hairy, so
  32.  *     load_image should be carefully tested to make sure there are no XBM's
  33.  *     that fail.
  34.  */
  35.  
  36. /* Set this for debugging. */
  37. /* #define VERBOSE 2 */
  38.  
  39. #include "config.h"
  40.  
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include <ctype.h>
  45.  
  46. #include <gtk/gtk.h>
  47.  
  48. #include <libgimp/gimp.h>
  49. #include <libgimp/gimpui.h>
  50.  
  51. #include "libgimp/stdplugins-intl.h"
  52.  
  53.  
  54. /* Wear your GIMP with pride! */
  55. #define DEFAULT_USE_COMMENT TRUE
  56. #define MAX_COMMENT         72
  57. #define MAX_MASK_EXT        32
  58.  
  59. /* C identifier prefix. */
  60. #define DEFAULT_PREFIX "bitmap"
  61. #define MAX_PREFIX     24
  62.  
  63. /* Whether or not to save as X10 bitmap. */
  64. #define DEFAULT_X10_FORMAT FALSE
  65.  
  66. typedef struct _XBMSaveVals
  67. {
  68.   gchar    comment[MAX_COMMENT + 1];
  69.   gint     x10_format;
  70.   gint     use_hot;
  71.   gint     x_hot;
  72.   gint     y_hot;
  73.   gchar    prefix[MAX_PREFIX + 1];
  74.   gboolean write_mask;
  75.   gchar    mask_ext[MAX_MASK_EXT + 1];
  76. } XBMSaveVals;
  77.  
  78. static XBMSaveVals xsvals =
  79. {
  80.   "###",        /* comment */
  81.   DEFAULT_X10_FORMAT,    /* x10_format */
  82.   FALSE,
  83.   0,            /* x_hot */
  84.   0,            /* y_hot */
  85.   DEFAULT_PREFIX,    /* prefix */
  86.   FALSE,                /* write_mask */
  87.   "_mask"
  88. };
  89.  
  90. typedef struct _XBMSaveInterface
  91. {
  92.   gint run;
  93. } XBMSaveInterface;
  94.  
  95. static XBMSaveInterface xsint =
  96. {
  97.   FALSE            /* run */
  98. };
  99.  
  100.  
  101. /* Declare some local functions.
  102.  */
  103. static void   query   (void);
  104. static void   run     (gchar      *name,
  105.                gint        nparams,
  106.                GimpParam  *param,
  107.                gint       *nreturn_vals,
  108.                GimpParam **return_vals);
  109.  
  110. static gint32 load_image              (gchar     *filename);
  111. static gint   save_image              (gchar     *filename,
  112.                        gchar     *prefix,
  113.                        gboolean   save_mask,
  114.                        gint32     image_ID, 
  115.                        gint32     drawable_ID);
  116. static gint   save_dialog             (gint32     drawable_ID);
  117. static void   save_ok_callback        (GtkWidget *widget,
  118.                        gpointer   data);
  119. #if 0
  120. /* DISABLED - see http://bugzilla.gnome.org/show_bug.cgi?id=82763 */
  121. static void   comment_entry_callback  (GtkWidget *widget,
  122.                        gpointer   data);
  123. #endif
  124. static void   prefix_entry_callback   (GtkWidget *widget,
  125.                        gpointer   data);
  126. static void   mask_ext_entry_callback (GtkWidget *widget,
  127.                        gpointer   data);
  128.  
  129. GimpPlugInInfo PLUG_IN_INFO =
  130. {
  131.   NULL,  /* init_proc  */
  132.   NULL,  /* quit_proc  */
  133.   query, /* query_proc */
  134.   run,   /* run_proc   */
  135. };
  136.  
  137. MAIN ()
  138.  
  139. #ifdef VERBOSE
  140. static int verbose = VERBOSE;
  141. #endif
  142.  
  143. static void
  144. query (void)
  145. {
  146.   static GimpParamDef load_args[] =
  147.   {
  148.     { GIMP_PDB_INT32,  "run_mode",     "Interactive, non-interactive" },
  149.     { GIMP_PDB_STRING, "filename",     "The name of the file to load" },
  150.     { GIMP_PDB_STRING, "raw_filename", "The name entered" }
  151.   };
  152.   static gint nload_args = sizeof (load_args) / sizeof (load_args[0]);
  153.  
  154.   static GimpParamDef load_return_vals[] =
  155.   {
  156.     { GIMP_PDB_IMAGE,  "image",        "Output image" }
  157.   };
  158.   static gint nload_return_vals = (sizeof (load_return_vals) /
  159.                    sizeof (load_return_vals[0]));
  160.  
  161.   static GimpParamDef save_args[] =
  162.   {
  163.     { GIMP_PDB_INT32,    "run_mode",       "Interactive, non-interactive" },
  164.     { GIMP_PDB_IMAGE,    "image",          "Input image" },
  165.     { GIMP_PDB_DRAWABLE, "drawable",       "Drawable to save" },
  166.     { GIMP_PDB_STRING,   "filename",       "The name of the file to save" },
  167.     { GIMP_PDB_STRING,   "raw_filename",   "The name entered" },
  168.     { GIMP_PDB_STRING,   "comment",        "Image description (maximum 72 bytes)" },
  169.     { GIMP_PDB_INT32,    "x10",            "Save in X10 format" },
  170.     { GIMP_PDB_INT32,    "x_hot",          "X coordinate of hotspot" },
  171.     { GIMP_PDB_INT32,    "y_hot",          "Y coordinate of hotspot" },
  172.     { GIMP_PDB_STRING,   "prefix",         "Identifier prefix [determined from filename]"},
  173.     { GIMP_PDB_INT32,    "write_mask",     "(0 = ignore, 1 = save as extra file)" },
  174.     { GIMP_PDB_STRING,   "mask_extension", "Extension of the mask file" }
  175.   } ;
  176.   static gint nsave_args = sizeof (save_args) / sizeof (save_args[0]);
  177.  
  178.   gimp_install_procedure ("file_xbm_load",
  179.                           "Load a file in X10 or X11 bitmap (XBM) file format",
  180.                           "Load a file in X10 or X11 bitmap (XBM) file format.  XBM is a lossless format for flat black-and-white (two color indexed) images.",
  181.                           "Gordon Matzigkeit",
  182.                           "Gordon Matzigkeit",
  183.                           "1998",
  184.                           "<Load>/XBM",
  185.               NULL,
  186.                           GIMP_PLUGIN,
  187.                           nload_args, nload_return_vals,
  188.                           load_args, load_return_vals);
  189.  
  190.   gimp_install_procedure ("file_xbm_save",
  191.                           "Save a file in X10 or X11 bitmap (XBM) file format",
  192.                           "Save a file in X10 or X11 bitmap (XBM) file format.  XBM is a lossless format for flat black-and-white (two color indexed) images.",
  193.               "Gordon Matzigkeit",
  194.                           "Gordon Matzigkeit",
  195.                           "1998",
  196.                           "<Save>/XBM",
  197.               "INDEXED",
  198.                           GIMP_PLUGIN,
  199.                           nsave_args, 0,
  200.                           save_args, NULL);
  201.  
  202.   gimp_register_load_handler ("file_xbm_load",
  203.                   "xbm,icon,bitmap",
  204.                   "");
  205.   gimp_register_save_handler ("file_xbm_save",
  206.                   "xbm,icon,bitmap",
  207.                   "");
  208. }
  209.  
  210. static gchar *
  211. init_prefix (gchar *filename)
  212. {
  213.   gchar *p, *prefix;
  214.   gint len;
  215.  
  216.   prefix = g_basename (filename);
  217.  
  218.   /* Strip any extension. */
  219.   p = strrchr (prefix, '.');
  220.   if (p && p != prefix)
  221.     len = MIN (MAX_PREFIX, p - prefix);
  222.   else
  223.     len = MAX_PREFIX;
  224.  
  225.   memset (xsvals.prefix, 0, sizeof (xsvals.prefix));
  226.   strncpy (xsvals.prefix, prefix, len);
  227.  
  228.   return xsvals.prefix;
  229. }
  230.  
  231. static void
  232. run (gchar      *name,
  233.      gint        nparams,
  234.      GimpParam  *param,
  235.      gint       *nreturn_vals,
  236.      GimpParam **return_vals)
  237. {
  238.   static GimpParam   values[2];
  239.   GimpRunModeType    run_mode;
  240.   GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
  241.   gint32             image_ID;
  242.   gint32             drawable_ID;
  243.   GimpParasite      *parasite = NULL; 
  244.   gchar             *mask_filename = NULL;
  245.   GimpExportReturnType export = GIMP_EXPORT_CANCEL;
  246.  
  247.   INIT_I18N_UI();
  248.   strncpy (xsvals.comment, _("Created with The GIMP"), MAX_COMMENT);
  249.  
  250.   run_mode = param[0].data.d_int32;
  251.  
  252.   *nreturn_vals = 1;
  253.   *return_vals  = values;
  254.   values[0].type          = GIMP_PDB_STATUS;
  255.   values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
  256.  
  257. #ifdef VERBOSE
  258.   if (verbose)
  259.     printf ("XBM: RUN %s\n", name);
  260. #endif
  261.  
  262.   if (strcmp (name, "file_xbm_load") == 0)
  263.     {
  264.       image_ID = load_image (param[1].data.d_string);
  265.  
  266.       if (image_ID != -1)
  267.         {
  268.           *nreturn_vals = 2;
  269.           values[1].type         = GIMP_PDB_IMAGE;
  270.           values[1].data.d_image = image_ID;
  271.         }
  272.       else
  273.         {
  274.           status = GIMP_PDB_EXECUTION_ERROR;
  275.         }
  276.     }
  277.   else if (strcmp (name, "file_xbm_save") == 0)
  278.     {
  279.       image_ID = param[1].data.d_int32;
  280.       drawable_ID = param[2].data.d_int32;
  281.  
  282.       /*  eventually export the image */ 
  283.       switch (run_mode)
  284.     {
  285.     case GIMP_RUN_INTERACTIVE:
  286.     case GIMP_RUN_WITH_LAST_VALS:
  287.       gimp_ui_init ("xbm", FALSE);
  288.       export = gimp_export_image (&image_ID, &drawable_ID, "XBM",
  289.                       GIMP_EXPORT_CAN_HANDLE_INDEXED |
  290.                       GIMP_EXPORT_CAN_HANDLE_ALPHA );
  291.       if (export == GIMP_EXPORT_CANCEL)
  292.         {
  293.           values[0].data.d_status = GIMP_PDB_CANCEL;
  294.           return;
  295.       }
  296.       break;
  297.     default:
  298.       break;
  299.     }
  300.  
  301.       switch (run_mode)
  302.     {
  303.     case GIMP_RUN_INTERACTIVE:
  304.     case GIMP_RUN_WITH_LAST_VALS:
  305.       /*  Possibly retrieve data  */
  306.       gimp_get_data ("file_xbm_save", &xsvals);
  307.  
  308.       /* Always override the prefix with the filename. */
  309.       mask_filename = g_strdup (init_prefix (param[3].data.d_string));
  310.       break;
  311.  
  312.     case GIMP_RUN_NONINTERACTIVE:
  313.       /*  Make sure all the required arguments are there!  */
  314.       if (nparams < 5)
  315.         {
  316.           status = GIMP_PDB_CALLING_ERROR;
  317.         }
  318.       else
  319.         {
  320.           gint i = 5;
  321.  
  322.           if (nparams > i)
  323.         {
  324.           memset (xsvals.comment, 0, sizeof (xsvals.comment));
  325.           strncpy (xsvals.comment, param[i].data.d_string,
  326.                MAX_COMMENT);
  327.         }
  328.  
  329.           i ++;
  330.           if (nparams > i)
  331.         xsvals.x10_format = (param[i].data.d_int32) ? TRUE : FALSE;
  332.  
  333.           i += 2;
  334.           if (nparams > i)
  335.         {
  336.           /* They've asked for a hotspot. */
  337.           xsvals.use_hot = TRUE;
  338.           xsvals.x_hot = param[i - 1].data.d_int32;
  339.           xsvals.y_hot = param[i].data.d_int32;
  340.         }
  341.  
  342.           mask_filename = g_strdup (init_prefix (param[3].data.d_string));
  343.  
  344.           i ++;
  345.           if (nparams > i)
  346.         {
  347.           memset (xsvals.prefix, 0, sizeof (xsvals.prefix));
  348.           strncpy (xsvals.prefix, param[i].data.d_string,
  349.                MAX_PREFIX);
  350.         }
  351.  
  352.           i += 2;
  353.           if (nparams > i)
  354.         {
  355.           xsvals.write_mask = param[i - 1].data.d_int32;
  356.           memset (xsvals.mask_ext, 0, sizeof (xsvals.mask_ext));
  357.           strncpy (xsvals.mask_ext, param[i].data.d_string,
  358.                MAX_MASK_EXT);
  359.         }
  360.  
  361.           i ++;
  362.           /* Too many arguments. */
  363.           if (nparams > i)
  364.         status = GIMP_PDB_CALLING_ERROR;
  365.         }
  366.       break;
  367.  
  368.     default:
  369.       break;
  370.     }
  371.  
  372.       if (run_mode == GIMP_RUN_INTERACTIVE)
  373.     {
  374.       /* Get the parasites */
  375.           parasite = gimp_image_parasite_find (image_ID, "gimp-comment");
  376.  
  377.           if (parasite)
  378.             {
  379.           gpointer data;
  380.           gint     size;
  381.  
  382.           data = gimp_parasite_data (parasite);
  383.           size = gimp_parasite_data_size (parasite);
  384.  
  385.           strncpy (xsvals.comment, data, MIN (size, MAX_COMMENT));
  386.           xsvals.comment[MIN (size, MAX_COMMENT) + 1] = 0;
  387.  
  388.           gimp_parasite_free (parasite);
  389.         }
  390.  
  391.           parasite = gimp_image_parasite_find (image_ID, "hot-spot");
  392.  
  393.           if (parasite)
  394.         {
  395.           gpointer data;
  396.           gint     x, y;
  397.  
  398.           data = gimp_parasite_data (parasite);
  399.  
  400.           if (sscanf (data, "%i %i", &x, &y) == 2)
  401.            {
  402.              xsvals.use_hot = TRUE;
  403.              xsvals.x_hot = x;
  404.              xsvals.y_hot = y;
  405.            }
  406.          gimp_parasite_free (parasite);
  407.        }
  408.  
  409.       /*  Acquire information with a dialog  */
  410.       if (! save_dialog (drawable_ID))
  411.         status = GIMP_PDB_CANCEL;
  412.     }
  413.  
  414.       if (status == GIMP_PDB_SUCCESS)
  415.     {
  416.       gchar *temp;
  417.       gchar *mask_prefix;
  418.       gchar *dirname;
  419.  
  420.       temp = mask_filename;
  421.  
  422.       if ((dirname = g_dirname (param[3].data.d_string)) != NULL)
  423.         {
  424.           mask_filename = g_strdup_printf ("%s/%s%s.xbm",
  425.                            dirname, temp, xsvals.mask_ext);
  426.           g_free (dirname);
  427.         }
  428.       else
  429.         {
  430.           mask_filename = g_strdup_printf ("%s%s.xbm",
  431.                            temp, xsvals.mask_ext);
  432.         }
  433.  
  434.       g_free (temp);
  435.  
  436.       /* Change any non-alphanumeric prefix characters to underscores. */
  437.       temp = xsvals.prefix;
  438.       while (*temp)
  439.         {
  440.           if (!isalnum (*temp))
  441.         *temp = '_';
  442.           temp ++;
  443.         }
  444.  
  445.       mask_prefix = g_strdup_printf ("%s%s", xsvals.prefix, xsvals.mask_ext);
  446.  
  447.       if (save_image (param[3].data.d_string,
  448.               xsvals.prefix,
  449.               FALSE,
  450.               image_ID, drawable_ID) 
  451.               && (!xsvals.write_mask || save_image (mask_filename,
  452.                                                     mask_prefix,
  453.                                                     TRUE,
  454.                                                     image_ID, drawable_ID)))
  455.         {
  456.           /*  Store xsvals data  */
  457.           gimp_set_data ("file_xbm_save", &xsvals, sizeof (xsvals));
  458.         }
  459.       else
  460.         {
  461.           status = GIMP_PDB_EXECUTION_ERROR;
  462.         }
  463.  
  464.       g_free (mask_prefix);
  465.       g_free (mask_filename);
  466.     }
  467.  
  468.       if (export == GIMP_EXPORT_EXPORT)
  469.     gimp_image_delete (image_ID);
  470.     }
  471.   else
  472.     {
  473.       status = GIMP_PDB_CALLING_ERROR;
  474.     }
  475.  
  476.   values[0].data.d_status = status;
  477. }
  478.  
  479.  
  480. /* Return the value of a digit. */
  481. static gint
  482. getval (gint c, 
  483.     gint base)
  484. {
  485.   static guchar *digits = "0123456789abcdefABCDEF";
  486.   gint val;
  487.  
  488.   /* Include uppercase hex digits. */
  489.   if (base == 16)
  490.     base = 22;
  491.  
  492.   /* Find a match. */
  493.   for (val = 0; val < base; val ++)
  494.     if (c == digits[val])
  495.       return (val < 16) ? val : (val - 6);
  496.   return -1;
  497. }
  498.  
  499.  
  500. /* Get a comment */
  501. static gchar *
  502. fgetcomment (FILE *fp)
  503. {
  504.   GString *str = NULL;
  505.   gint comment, c;
  506.  
  507.   comment = 0;
  508.   do
  509.     {
  510.       c = fgetc (fp);
  511.       if (comment)
  512.     {
  513.       if (c == '*')
  514.         {
  515.           /* In a comment, with potential to leave. */
  516.           comment = 1;
  517.         }
  518.       else if (comment == 1 && c == '/')
  519.         {
  520.           gchar *retval;
  521.  
  522.           /* Leaving a comment. */
  523.           comment = 0;
  524.  
  525.           retval = g_strstrip (g_strdup (str->str));
  526.           g_string_free (str, TRUE);
  527.           return retval;
  528.         }
  529.       else
  530.         {
  531.           /* In a comment, with no potential to leave. */
  532.           comment = 2;
  533.           g_string_append_c (str, c);
  534.         }
  535.     }
  536.       else
  537.     {
  538.       /* Not in a comment. */
  539.       if (c == '/')
  540.         {
  541.           /* Potential to enter a comment. */
  542.           c = fgetc (fp);
  543.           if (c == '*')
  544.         {
  545.           /* Entered a comment, with no potential to leave. */
  546.           comment = 2;
  547.           str = g_string_new (NULL);
  548.         }
  549.           else
  550.         {
  551.           /* put everything back and return */
  552.           ungetc (c, fp);
  553.           c = '/';
  554.           ungetc (c, fp);
  555.           return NULL;
  556.         }
  557.         }
  558.       else if (isspace (c))
  559.         {
  560.           /* Skip leading whitespace */
  561.           continue;
  562.         }
  563.     }
  564.     }
  565.   while (comment && c != EOF);
  566.  
  567.   if (str)
  568.     g_string_free (str, TRUE);
  569.  
  570.   return NULL;
  571. }
  572.  
  573.  
  574. /* Same as fgetc, but skip C-style comments and insert whitespace. */
  575. static gint
  576. cpp_fgetc (FILE *fp)
  577. {
  578.   gint comment, c;
  579.  
  580.   /* FIXME: insert whitespace as advertised. */
  581.   comment = 0;
  582.   do
  583.     {
  584.       c = fgetc (fp);
  585.       if (comment)
  586.     {
  587.       if (c == '*')
  588.         /* In a comment, with potential to leave. */
  589.         comment = 1;
  590.       else if (comment == 1 && c == '/')
  591.         /* Leaving a comment. */
  592.         comment = 0;
  593.       else
  594.         /* In a comment, with no potential to leave. */
  595.         comment = 2;
  596.     }
  597.       else
  598.     {
  599.       /* Not in a comment. */
  600.       if (c == '/')
  601.         {
  602.           /* Potential to enter a comment. */
  603.           c = fgetc (fp);
  604.           if (c == '*')
  605.         /* Entered a comment, with no potential to leave. */
  606.         comment = 2;
  607.           else
  608.         {
  609.           /* Just a slash in the open. */
  610.           ungetc (c, fp);
  611.           c = '/';
  612.         }
  613.         }
  614.     }
  615.     }
  616.   while (comment && c != EOF);
  617.   return c;
  618. }
  619.  
  620.  
  621. /* Match a string with a file. */
  622. static gint
  623. match (FILE  *fp, 
  624.        gchar *s)
  625. {
  626.   gint c;
  627.  
  628.   do
  629.     {
  630.       c = fgetc (fp);
  631.       if (c == *s)
  632.     s ++;
  633.       else
  634.     break;
  635.     }
  636.   while (c != EOF && *s);
  637.  
  638.   if (!*s)
  639.     return TRUE;
  640.  
  641.   if (c != EOF)
  642.     ungetc (c, fp);
  643.   return FALSE;
  644. }
  645.  
  646.  
  647. /* Read the next integer from the file, skipping all non-integers. */
  648. static gint
  649. get_int (FILE *fp)
  650. {
  651.   int digval, base, val, c;
  652.  
  653.   do
  654.     c = cpp_fgetc (fp);
  655.   while (c != EOF && !isdigit (c));
  656.  
  657.   if (c == EOF)
  658.     return 0;
  659.  
  660.   /* Check for the base. */
  661.   if (c == '0')
  662.     {
  663.       c = fgetc (fp);
  664.       if (c == 'x' || c == 'X')
  665.     {
  666.       c = fgetc (fp);
  667.       base = 16;
  668.     }
  669.       else if (isdigit (c))
  670.     base = 8;
  671.       else
  672.     {
  673.       ungetc (c, fp);
  674.       return 0;
  675.     }
  676.     }
  677.   else
  678.     base = 10;
  679.  
  680.   val = 0;
  681.   for (;;)
  682.     {
  683.       digval = getval (c, base);
  684.       if (digval == -1)
  685.     {
  686.       ungetc (c, fp);
  687.       break;
  688.     }
  689.       val *= base;
  690.       val += digval;
  691.       c = fgetc (fp);
  692.     }
  693.  
  694.   return val;
  695. }
  696.  
  697.  
  698. static gint
  699. load_image (gchar *filename)
  700. {
  701.   FILE *fp;
  702.   gint32 image_ID, layer_ID;
  703.  
  704.   GimpPixelRgn  pixel_rgn;
  705.   GimpDrawable *drawable;
  706.   guchar *data;
  707.   gint    intbits;
  708.   gint    width = 0;
  709.   gint    height = 0;
  710.   gint    x_hot = 0;
  711.   gint    y_hot = 0;
  712.   gint    c, i, j, k;
  713.   gint    tileheight, rowoffset;
  714.  
  715.   gchar *name_buf;
  716.   gchar *comment;
  717.  
  718.   guchar cmap[] =
  719.   {
  720.     0x00, 0x00, 0x00,        /* black */
  721.     0xff, 0xff, 0xff        /* white */
  722.   };
  723.  
  724.   fp = fopen (filename, "rb");
  725.   if (!fp)
  726.     {
  727.       g_message (_("XBM: cannot open \"%s\"\n"), filename);
  728.       return -1;
  729.     }
  730.  
  731.   name_buf = g_strdup_printf (_("Loading %s:"), filename);
  732.   gimp_progress_init (name_buf);
  733.   g_free (name_buf);
  734.  
  735.   comment = fgetcomment (fp);
  736.  
  737.   /* Loosely parse the header */
  738.   intbits = height = width = 0;
  739.   c = ' ';
  740.   do
  741.     {
  742.       if (isspace (c))
  743.     {
  744.       if (match (fp, "char"))
  745.         {
  746.           c = fgetc (fp);
  747.           if (isspace (c))
  748.         {
  749.           intbits = 8;
  750.           continue;
  751.         }
  752.         }
  753.       else if (match (fp, "short"))
  754.         {
  755.           c = fgetc (fp);
  756.           if (isspace (c))
  757.         {
  758.           intbits = 16;
  759.           continue;
  760.         }
  761.         }
  762.     }
  763.  
  764.       if (c == '_')
  765.     {
  766.       if (match (fp, "width"))
  767.         {
  768.           c = fgetc (fp);
  769.           if (isspace (c))
  770.         {
  771.           width = get_int (fp);
  772.           continue;
  773.         }
  774.         }
  775.       else if (match (fp, "height"))
  776.         {
  777.           c = fgetc (fp);
  778.           if (isspace (c))
  779.         {
  780.           height = get_int (fp);
  781.           continue;
  782.         }
  783.         }
  784.       else if (match (fp, "x_hot"))
  785.         {
  786.           c = fgetc (fp);
  787.           if (isspace (c))
  788.         {
  789.           x_hot = get_int (fp);
  790.           continue;
  791.         }
  792.         }
  793.       else if (match (fp, "y_hot"))
  794.         {
  795.           c = fgetc (fp);
  796.           if (isspace (c))
  797.         {
  798.           y_hot = get_int (fp);
  799.           continue;
  800.         }
  801.         }
  802.     }
  803.  
  804.       c = cpp_fgetc (fp);
  805.     }
  806.   while (c != '{' && c != EOF);
  807.  
  808.   if (c == EOF)
  809.     {
  810.       g_message (_("XBM: cannot read header (ftell == %ld)\n"), ftell (fp));
  811.       return -1;
  812.     }
  813.  
  814.   if (width == 0)
  815.     {
  816.       g_message (_("XBM: no image width specified\n"));
  817.       return -1;
  818.     }
  819.  
  820.   if (height == 0)
  821.     {
  822.       g_message (_("XBM: no image height specified\n"));
  823.       return -1;
  824.     }
  825.  
  826.   if (intbits == 0)
  827.     {
  828.       g_message (_("XBM: no image data type specified\n"));
  829.       return -1;
  830.     }
  831.  
  832.   image_ID = gimp_image_new (width, height, GIMP_INDEXED);
  833.   gimp_image_set_filename (image_ID, filename);
  834.  
  835.   if (comment)
  836.     {
  837.       GimpParasite *parasite;
  838.  
  839.       parasite = gimp_parasite_new ("gimp-comment",
  840.                     GIMP_PARASITE_PERSISTENT,
  841.                     strlen (comment) + 1, (gpointer) comment);
  842.       gimp_image_parasite_attach (image_ID, parasite);
  843.       gimp_parasite_free (parasite);
  844.  
  845.       g_free (comment);
  846.     }
  847.  
  848.   x_hot = CLAMP (x_hot, 0, width);
  849.   y_hot = CLAMP (y_hot, 0, height);
  850.  
  851.   if (x_hot > 0 || y_hot > 0)
  852.     {
  853.       GimpParasite *parasite;
  854.       gchar        *str;
  855.  
  856.       str = g_strdup_printf ("%d %d", x_hot, y_hot);
  857.       parasite = gimp_parasite_new ("hot-spot",
  858.                     GIMP_PARASITE_PERSISTENT,
  859.                     strlen (str) + 1, (gpointer) str);
  860.       g_free (str);
  861.       gimp_image_parasite_attach (image_ID, parasite);
  862.       gimp_parasite_free (parasite);
  863.     }
  864.  
  865.   /* Set a black-and-white colormap. */
  866.   gimp_image_set_cmap (image_ID, cmap, 2);
  867.  
  868.   layer_ID = gimp_layer_new (image_ID,
  869.                  _("Background"),
  870.                  width, height,
  871.                  GIMP_INDEXED_IMAGE,
  872.                  100,
  873.                  GIMP_NORMAL_MODE);
  874.   gimp_image_add_layer (image_ID, layer_ID, 0);
  875.  
  876.   drawable = gimp_drawable_get (layer_ID);
  877.  
  878.   /* Prepare the pixel region. */
  879.   gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, width, height, TRUE, FALSE);
  880.  
  881.   /* Allocate the data. */
  882.   tileheight = gimp_tile_height ();
  883.   data = (guchar *) g_malloc (width * tileheight);
  884.  
  885.   for (i = 0; i < height; i += tileheight)
  886.     {
  887.       tileheight = MIN (tileheight, height - i);
  888.  
  889. #ifdef VERBOSE
  890.       if (verbose > 1)
  891.     printf ("XBM: reading %dx(%d+%d) pixel region\n", width, i,
  892.         tileheight);
  893. #endif
  894.  
  895.       /* Parse the data from the file */
  896.       for (j = 0; j < tileheight; j ++)
  897.     {
  898.       /* Read each row. */
  899.       rowoffset = j * width;
  900.       for (k = 0; k < width; k ++)
  901.         {
  902.           /* Expand each integer into INTBITS pixels. */
  903.           if (k % intbits == 0)
  904.         {
  905.           c = get_int (fp);
  906.  
  907.           /* Flip all the bits so that 1's become black and
  908.                      0's become white. */
  909.           c ^= 0xffff;
  910.         }
  911.  
  912.           data[rowoffset + k] = c & 1;
  913.           c >>= 1;
  914.         }
  915.     }
  916.  
  917.       /* Put the data into the image. */
  918.       gimp_progress_update ((double) (i + tileheight) / (double) height);
  919.       gimp_pixel_rgn_set_rect (&pixel_rgn, data, 0, i, width, tileheight);
  920.     }
  921.  
  922.   g_free (data);
  923.  
  924.   gimp_drawable_flush (drawable);
  925.   gimp_drawable_detach (drawable);
  926.  
  927.   fclose (fp);
  928.  
  929.   return image_ID;
  930. }
  931.  
  932. static gboolean
  933. save_image (gchar    *filename,
  934.         gchar    *prefix,
  935.         gboolean  save_mask,
  936.         gint32    image_ID,
  937.         gint32    drawable_ID)
  938. {
  939.   GimpDrawable *drawable;
  940.   GimpPixelRgn  pixel_rgn;
  941.   FILE *fp;
  942.  
  943.   gint width, height, colors, dark;
  944.   gint intbits, lineints, need_comma, nints, rowoffset, tileheight;
  945.   gint c, i, j, k, thisbit;
  946.  
  947.   gboolean has_alpha;
  948.   gint     bpp;
  949.  
  950.   guchar *data, *cmap, *name_buf, *intfmt;
  951.  
  952.   drawable = gimp_drawable_get (drawable_ID);
  953.   width  = drawable->width;
  954.   height = drawable->height;
  955.   cmap = gimp_image_get_cmap (image_ID, &colors);
  956.  
  957.   if (!gimp_drawable_is_indexed (drawable_ID) || colors > 2)
  958.     {
  959.       /* The image is not black-and-white. */
  960.       g_message (_("The image which you are trying to save as\n"
  961.            "an XBM contains more than two colors.\n\n"
  962.            "Please convert it to a black and white\n"
  963.            "(1-bit) indexed image and try again."));
  964.       return FALSE;
  965.     }
  966.  
  967.   has_alpha = gimp_drawable_has_alpha (drawable_ID);
  968.  
  969.   if (!has_alpha && save_mask)
  970.     {
  971.       g_message (_("You cannot save a cursor mask for an image\n"
  972.            "which has no alpha channel."));
  973.       return FALSE;
  974.     }
  975.  
  976.   bpp = gimp_drawable_bpp (drawable_ID);
  977.  
  978.   name_buf = g_strdup_printf (_("Saving %s:"), filename);
  979.   gimp_progress_init (name_buf);
  980.   g_free (name_buf);
  981.  
  982.   /* Figure out which color is black, and which is white. */
  983.   dark = 0;
  984.   if (colors > 1)
  985.     {
  986.       gint first, second;
  987.  
  988.       /* Maybe the second color is darker than the first. */
  989.       first  = (cmap[0] * cmap[0]) + (cmap[1] * cmap[1]) + (cmap[2] * cmap[2]);
  990.       second = (cmap[3] * cmap[3]) + (cmap[4] * cmap[4]) + (cmap[5] * cmap[5]);
  991.  
  992.       if (second < first)
  993.     dark = 1;
  994.     }
  995.  
  996.   /* Now actually save the data. */
  997.   fp = fopen (filename, "w");
  998.   if (!fp)
  999.     {
  1000.       g_message (_("XBM: cannot create \"%s\"\n"), filename);
  1001.       return FALSE;
  1002.     }
  1003.  
  1004. #if 0
  1005.   /* Maybe write the image comment. */
  1006.   /* DISABLED - see http://bugzilla.gnome.org/show_bug.cgi?id=82763 */
  1007.   /* a future version should write the comment at the end of the file */
  1008.   if (*comment)
  1009.     fprintf (fp, "/* %s */\n", comment);
  1010. #endif
  1011.  
  1012.   /* Write out the image height and width. */
  1013.   fprintf (fp, "#define %s_width %d\n",  prefix, width);
  1014.   fprintf (fp, "#define %s_height %d\n", prefix, height);
  1015.  
  1016.   /* Write out the hotspot, if any. */
  1017.   if (xsvals.use_hot)
  1018.     {
  1019.       fprintf (fp, "#define %s_x_hot %d\n", prefix, xsvals.x_hot);
  1020.       fprintf (fp, "#define %s_y_hot %d\n", prefix, xsvals.y_hot);
  1021.     }
  1022.  
  1023.   /* Now write the actual data. */
  1024.   if (xsvals.x10_format)
  1025.     {
  1026.       /* We can fit 9 hex shorts on a single line. */
  1027.       lineints = 9;
  1028.       intbits = 16;
  1029.       intfmt = " 0x%04x";
  1030.     }
  1031.   else
  1032.     {
  1033.       /* We can fit 12 hex chars on a single line. */
  1034.       lineints = 12;
  1035.       intbits = 8;
  1036.       intfmt = " 0x%02x";
  1037.     }
  1038.  
  1039.   fprintf (fp, "static %s %s_bits[] = {\n  ",
  1040.        xsvals.x10_format ? "unsigned short" : "unsigned char", prefix);
  1041.  
  1042.   /* Allocate a new set of pixels. */
  1043.   tileheight = gimp_tile_height ();
  1044.   data = (guchar *) g_malloc (width * tileheight * bpp);
  1045.  
  1046.   gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, width, height,
  1047.                FALSE, FALSE);
  1048.  
  1049.   /* Write out the integers. */
  1050.   need_comma = 0;
  1051.   nints = 0;
  1052.   for (i = 0; i < height; i += tileheight)
  1053.     {
  1054.       /* Get a horizontal slice of the image. */
  1055.       tileheight = MIN (tileheight, height - i);
  1056.       gimp_pixel_rgn_get_rect (&pixel_rgn, data, 0, i, width, tileheight);
  1057.  
  1058. #ifdef VERBOSE
  1059.       if (verbose > 1)
  1060.     printf ("TGA: writing %dx(%d+%d) pixel region\n",
  1061.         width, i, tileheight);
  1062. #endif
  1063.  
  1064.       for (j = 0; j < tileheight; j ++)
  1065.     {
  1066.       /* Write out a row at a time. */
  1067.       rowoffset = j * width * bpp;
  1068.       c = 0;
  1069.       thisbit = 0;
  1070.  
  1071.       for (k = 0; k < width * bpp; k += bpp)
  1072.         {
  1073.           if (k != 0 && thisbit == intbits)
  1074.         {
  1075.           /* Output a completed integer. */
  1076.           if (need_comma)
  1077.             fputc (',', fp);
  1078.           need_comma = 1;
  1079.  
  1080.           /* Maybe start a new line. */
  1081.           if (nints ++ >= lineints)
  1082.             {
  1083.               nints = 1;
  1084.               fputs ("\n  ", fp);
  1085.             }
  1086.           fprintf (fp, intfmt, c);
  1087.  
  1088.           /* Start a new integer. */
  1089.           c = 0;
  1090.           thisbit = 0;
  1091.         }
  1092.  
  1093.           /* Pack INTBITS pixels into an integer. */
  1094.           if (save_mask)
  1095.         {
  1096.           c |= ((data[rowoffset + k + 1] < 128) ? 0 : 1) << (thisbit ++);
  1097.         }
  1098.           else
  1099.         {
  1100.           if (has_alpha && (data[rowoffset + k + 1] < 128))
  1101.             c |= 0 << (thisbit ++);
  1102.           else
  1103.             c |= ((data[rowoffset + k] == dark) ? 1 : 0) << (thisbit ++);
  1104.         }
  1105.         }
  1106.  
  1107.       if (thisbit != 0)
  1108.         {
  1109.           /* Write out the last oddball int. */
  1110.           if (need_comma)
  1111.         fputc (',', fp);
  1112.           need_comma = 1;
  1113.  
  1114.           /* Maybe start a new line. */
  1115.           if (nints ++ == lineints)
  1116.         {
  1117.           nints = 1;
  1118.           fputs ("\n  ", fp);
  1119.         }
  1120.           fprintf (fp, intfmt, c);
  1121.         }
  1122.     }
  1123.  
  1124.       gimp_progress_update ((double) (i + tileheight) / (double) height);
  1125.     }
  1126.  
  1127.   /* Write the trailer. */
  1128.   fprintf (fp, " };\n");
  1129.   fclose (fp);
  1130.   return TRUE;
  1131. }
  1132.  
  1133. static gint
  1134. save_dialog (gint32 drawable_ID)
  1135. {
  1136.   GtkWidget *dlg;
  1137.   GtkWidget *frame;
  1138.   GtkWidget *vbox;
  1139.   GtkWidget *toggle;
  1140.   GtkWidget *table;
  1141.   GtkWidget *entry;
  1142.   GtkWidget *spinbutton;
  1143.   GtkObject *adj;
  1144.  
  1145.   dlg = gimp_dialog_new (_("Save as XBM"), "xbm",
  1146.              gimp_standard_help_func, "filters/xbm.html",
  1147.              GTK_WIN_POS_MOUSE,
  1148.              FALSE, TRUE, FALSE,
  1149.  
  1150.              _("OK"), save_ok_callback,
  1151.              NULL, NULL, NULL, TRUE, FALSE,
  1152.              _("Cancel"), gtk_widget_destroy,
  1153.              NULL, 1, NULL, FALSE, TRUE,
  1154.  
  1155.              NULL);
  1156.  
  1157.   gtk_signal_connect (GTK_OBJECT (dlg), "destroy",
  1158.               GTK_SIGNAL_FUNC (gtk_main_quit),
  1159.               NULL);
  1160.  
  1161.   /* parameter settings */
  1162.   frame = gtk_frame_new (_("XBM Options"));
  1163.   gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
  1164.   gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
  1165.   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, TRUE, TRUE, 0);
  1166.   gtk_widget_show (frame);
  1167.  
  1168.   vbox = gtk_vbox_new (FALSE, 4);
  1169.   gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
  1170.   gtk_container_add (GTK_CONTAINER (frame), vbox);
  1171.  
  1172.   /*  X10 format  */
  1173.   toggle = gtk_check_button_new_with_label (_("X10 Format Bitmap"));
  1174.   gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
  1175.   gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
  1176.               GTK_SIGNAL_FUNC (gimp_toggle_button_update),
  1177.               &xsvals.x10_format);
  1178.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), xsvals.x10_format);
  1179.   gtk_widget_show (toggle);
  1180.  
  1181.   table = gtk_table_new (2, 2, FALSE);
  1182.   gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  1183.   gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  1184.   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
  1185.   gtk_widget_show (table);
  1186.  
  1187.   /* prefix */
  1188.   entry = gtk_entry_new_with_max_length (MAX_PREFIX);
  1189.   gtk_entry_set_text (GTK_ENTRY (entry), xsvals.prefix);
  1190.   gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
  1191.                  _("Identifier Prefix:"), 1.0, 0.5,
  1192.                  entry, 1, TRUE);
  1193.   gtk_signal_connect (GTK_OBJECT (entry), "changed",
  1194.                       GTK_SIGNAL_FUNC (prefix_entry_callback),
  1195.                       NULL);
  1196.  
  1197. #if 0
  1198.   /* comment string. */
  1199. #if 0
  1200.   /* DISABLED - see http://bugzilla.gnome.org/show_bug.cgi?id=82763 */
  1201.   entry = gtk_entry_new_with_max_length (MAX_COMMENT);
  1202.   gtk_widget_set_usize (entry, 240, 0);
  1203.   gtk_entry_set_text (GTK_ENTRY (entry), xsvals.comment);
  1204.   gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
  1205.                  _("Comment:"), 1.0, 0.5,
  1206.                  entry, 1, TRUE);
  1207.   gtk_signal_connect (GTK_OBJECT (entry), "changed",
  1208.                       GTK_SIGNAL_FUNC (comment_entry_callback),
  1209.                       NULL);
  1210. #endif
  1211.  
  1212.   /* hotspot toggle */
  1213.   toggle = gtk_check_button_new_with_label (_("Write Hot Spot Values"));
  1214.   gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
  1215.   gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
  1216.               GTK_SIGNAL_FUNC (gimp_toggle_button_update),
  1217.               &xsvals.use_hot);
  1218.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), xsvals.use_hot);
  1219.   gtk_widget_show (toggle);
  1220.  
  1221.   table = gtk_table_new (2, 2, FALSE);
  1222.   gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  1223.   gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  1224.   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
  1225.   gtk_widget_show (table);
  1226.  
  1227.   gtk_object_set_data (GTK_OBJECT (toggle), "set_sensitive", table);
  1228.   gtk_widget_set_sensitive (table, xsvals.use_hot);
  1229.  
  1230.   spinbutton = gimp_spin_button_new (&adj, xsvals.x_hot, 0,
  1231.                      gimp_drawable_width (drawable_ID) - 1,
  1232.                      1, 1, 1, 0, 0);
  1233.   gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
  1234.               GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
  1235.               &xsvals.x_hot);
  1236.   gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
  1237.                  _("Hot Spot X:"), 1.0, 0.5,
  1238.                  spinbutton, 1, TRUE);
  1239.  
  1240.   spinbutton = gimp_spin_button_new (&adj, xsvals.y_hot, 0,
  1241.                      gimp_drawable_height (drawable_ID) - 1,
  1242.                      1, 1, 1, 0, 0);
  1243.   gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
  1244.               GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
  1245.               &xsvals.y_hot);
  1246.   gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
  1247.                  _("Y:"), 1.0, 0.5,
  1248.                  spinbutton, 1, TRUE);
  1249.  
  1250.   /* mask file */
  1251.   frame = gtk_frame_new (_("Mask File"));
  1252.   gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  1253.   gtk_widget_show (frame);
  1254.  
  1255.   table = gtk_table_new (2, 2, FALSE);
  1256.   gtk_container_set_border_width (GTK_CONTAINER (table), 2);
  1257.   gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  1258.   gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  1259.   gtk_container_add (GTK_CONTAINER (frame), table);
  1260.   gtk_widget_show (table);
  1261.  
  1262.   toggle = gtk_check_button_new_with_label (_("Write Extra Mask File"));
  1263.   gtk_table_attach_defaults (GTK_TABLE (table), toggle, 0, 2, 0, 1);
  1264.   gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
  1265.               GTK_SIGNAL_FUNC (gimp_toggle_button_update),
  1266.               &xsvals.write_mask);
  1267.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), xsvals.write_mask);
  1268.   gtk_widget_show (toggle);
  1269.  
  1270.   entry = gtk_entry_new_with_max_length (MAX_MASK_EXT);
  1271.   gtk_entry_set_text (GTK_ENTRY (entry), xsvals.mask_ext);
  1272.   gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
  1273.                  _("Mask File Extension:"), 1.0, 0.5,
  1274.                  entry, 1, TRUE);
  1275.   gtk_signal_connect (GTK_OBJECT (entry), "changed",
  1276.                       GTK_SIGNAL_FUNC (mask_ext_entry_callback),
  1277.                       NULL);
  1278. #endif
  1279.  
  1280.   gtk_object_set_data (GTK_OBJECT (toggle), "set_sensitive", entry);
  1281.   gtk_widget_set_sensitive (entry, xsvals.write_mask);
  1282.  
  1283.   gtk_widget_set_sensitive (frame, gimp_drawable_has_alpha (drawable_ID));
  1284.  
  1285.   /* Done. */
  1286.   gtk_widget_show (vbox);
  1287.   gtk_widget_show (dlg);
  1288.  
  1289.   gtk_main ();
  1290.   gdk_flush ();
  1291.  
  1292.   return xsint.run;
  1293. }
  1294.  
  1295.  
  1296. /* Update the comment string. */
  1297. #if 0
  1298. /* DISABLED - see http://bugzilla.gnome.org/show_bug.cgi?id=82763 */
  1299. static void
  1300. comment_entry_callback (GtkWidget *widget,
  1301.             gpointer   data)
  1302. {
  1303.   memset (xsvals.comment, 0, sizeof (xsvals.comment));
  1304.   strncpy (xsvals.comment,
  1305.        gtk_entry_get_text (GTK_ENTRY (widget)), MAX_COMMENT);
  1306. }
  1307. #endif
  1308.  
  1309. static void
  1310. prefix_entry_callback (GtkWidget *widget,
  1311.                gpointer   data)
  1312. {
  1313.   memset (xsvals.prefix, 0, sizeof (xsvals.prefix));
  1314.   strncpy (xsvals.prefix,
  1315.        gtk_entry_get_text (GTK_ENTRY (widget)), MAX_PREFIX);
  1316. }
  1317.  
  1318. static void
  1319. mask_ext_entry_callback (GtkWidget *widget,
  1320.                gpointer   data)
  1321. {
  1322.   memset (xsvals.prefix, 0, sizeof (xsvals.mask_ext));
  1323.   strncpy (xsvals.mask_ext,
  1324.        gtk_entry_get_text (GTK_ENTRY (widget)), MAX_MASK_EXT);
  1325. }
  1326.  
  1327. static void
  1328. save_ok_callback (GtkWidget *widget,
  1329.           gpointer   data)
  1330. {
  1331.   xsint.run = TRUE;
  1332.  
  1333.   gtk_widget_destroy (GTK_WIDGET (data));
  1334. }
  1335.